﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace XEvents.Library
{
    internal struct server_event_session
    {
        internal int event_session_id;
        internal string name;
        internal char event_retention_mode;
        internal string event_retention_mode_desc;
        internal int max_dispatch_latency;
        internal int max_memory;
        internal int max_event_size;
        internal char memory_partition_mode;
        internal string memory_partition_mode_desc;
        internal bool track_causality;
        internal bool startup_state;

        internal server_event_session(SqlDataReader dr)
        {
            Int32.TryParse((dr["event_session_id"] == DBNull.Value ? "-1" : dr["event_session_id"]).ToString(), out event_session_id);
            name = (dr["name"] == DBNull.Value ? string.Empty : dr["name"]).ToString();
            Char.TryParse((dr["event_retention_mode"] == DBNull.Value ? string.Empty : dr["event_retention_mode"]).ToString(), out event_retention_mode);
            event_retention_mode_desc = (dr["event_retention_mode_desc"] == DBNull.Value ? string.Empty : dr["event_retention_mode_desc"]).ToString();
            Int32.TryParse((dr["max_dispatch_latency"] == DBNull.Value ? "-1" : dr["max_dispatch_latency"]).ToString(), out max_dispatch_latency);
            Int32.TryParse((dr["max_memory"] == DBNull.Value ? "-1" : dr["max_memory"]).ToString(), out max_memory);
            Int32.TryParse((dr["max_event_size"] == DBNull.Value ? "-1" : dr["max_event_size"]).ToString(), out max_event_size);
            Char.TryParse((dr["memory_partition_mode"] == DBNull.Value ? string.Empty : dr["memory_partition_mode"]).ToString(), out memory_partition_mode);
            memory_partition_mode_desc = (dr["memory_partition_mode_desc"] == DBNull.Value ? string.Empty : dr["memory_partition_mode_desc"]).ToString();
            Boolean.TryParse((dr["track_causality"] == DBNull.Value ? "-1" : dr["track_causality"]).ToString(), out track_causality);
            Boolean.TryParse((dr["startup_state"] == DBNull.Value ? "-1" : dr["startup_state"]).ToString(), out startup_state);
        }
    }
}
